<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Oxygine: oxygine/src/oxygine/EventDispatcher.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Oxygine
   &#160;<span id="projectnumber">1</span>
   </div>
   <div id="projectbrief">2g game engine</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_88d7b491052e55e71eacae831ff94513.html">oxygine</a></li><li class="navelem"><a class="el" href="dir_d6ad93a63bc66e9dc5661bef6ced2dac.html">src</a></li><li class="navelem"><a class="el" href="dir_d84c7f2cba023ce9bbd5251f35a25068.html">oxygine</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">EventDispatcher.h</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="preprocessor">#pragma once</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="preprocessor">#include &quot;oxygine-include.h&quot;</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="preprocessor">#include &quot;closure/closure.h&quot;</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="preprocessor">#include &quot;core/Object.h&quot;</span></div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#include &lt;list&gt;</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;</div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespaceoxygine.html">oxygine</a></div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;{</div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#define makefourcc(a,b,c,d) ( ((unsigned int)a) | (((unsigned int)b)&lt;&lt; 8) | (((unsigned int)c)&lt;&lt;16) | (((unsigned int)d)&lt;&lt;24))</span></div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;</div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#ifdef OX_HAS_CPP11</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;    <span class="keyword">inline</span> <span class="keywordtype">int</span> error_eventID_should_be_size_of_4_chars(<span class="keywordtype">int</span> x) { <span class="keywordflow">return</span> x; }</div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;    constexpr <span class="keywordtype">size_t</span> constStringLength(<span class="keyword">const</span> <span class="keywordtype">char</span>* str) { <span class="keywordflow">return</span> (*str == 0) ? 0 : constStringLength(str + 1) + 1; }</div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;    constexpr <span class="keywordtype">int</span> EventIDc11(<span class="keyword">const</span> <span class="keywordtype">char</span>* str) { <span class="keywordflow">return</span> constStringLength(str) == 4 ? makefourcc(str[0], str[1], str[2], str[3]) : error_eventID_should_be_size_of_4_chars(0); }</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="preprocessor">#endif</span></div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;</div><div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;    <span class="comment">//eventID(&#39;_&#39;, &#39;_&#39;, &#39;_&#39;, &#39;_&#39;)</span></div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="preprocessor">#define eventID(a,b,c,d) makefourcc(a,b,c,d)</span></div><div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;    <span class="comment">/*sysEventID is used for system Oxygine events, use &#39;eventID&#39; for custom game events*/</span></div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#define sysEventID(b,c,d) makefourcc(0xA,b,c,d)</span></div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#define  EventID(str) EventIDc11(str)</span></div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;    DECLARE_SMART(EventDispatcher, spEventDispatcher);</div><div class="line"><a name="l00027"></a><span class="lineno"><a class="line" href="classoxygine_1_1_event_dispatcher.html">   27</a></span>&#160;    <span class="keyword">class </span><a class="code" href="classoxygine_1_1_event_dispatcher.html">EventDispatcher</a>: <span class="keyword">public</span> <a class="code" href="classoxygine_1_1_object.html">Object</a></div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    {</div><div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;        INHERITED(<a class="code" href="classoxygine_1_1_object.html">Object</a>);</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;    <span class="keyword">public</span>:</div><div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;        <a class="code" href="classoxygine_1_1_event_dispatcher.html">EventDispatcher</a>(<span class="keyword">const</span> <a class="code" href="classoxygine_1_1_event_dispatcher.html">EventDispatcher</a>&amp; ed): inherited(ed), _lastID(0), _listeners(0) {}</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;        <a class="code" href="classoxygine_1_1_event_dispatcher.html">EventDispatcher</a>();</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;        ~<a class="code" href="classoxygine_1_1_event_dispatcher.html">EventDispatcher</a>();</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;        <span class="keywordtype">int</span> addEventListener(eventType, <span class="keyword">const</span> EventCallback&amp;);</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;        <span class="keywordtype">void</span> <a class="code" href="classoxygine_1_1_event_dispatcher.html#aea01fffe5e9ce057c6445da2661185e2">removeEventListener</a>(eventType, <span class="keyword">const</span> EventCallback&amp;);</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;        <span class="keywordtype">void</span> <a class="code" href="classoxygine_1_1_event_dispatcher.html#aea01fffe5e9ce057c6445da2661185e2">removeEventListener</a>(<span class="keywordtype">int</span> <span class="keywordtype">id</span>);</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;        <span class="keywordtype">bool</span> <a class="code" href="classoxygine_1_1_event_dispatcher.html#a0b605ef8cb965cc96b642f9c2649fc40">hasEventListeners</a>(<span class="keywordtype">void</span>* CallbackThis);</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;        <span class="keywordtype">bool</span> <a class="code" href="classoxygine_1_1_event_dispatcher.html#a0b605ef8cb965cc96b642f9c2649fc40">hasEventListeners</a>(eventType, <span class="keyword">const</span> EventCallback&amp;);</div><div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;</div><div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;        <span class="keywordtype">void</span> <a class="code" href="classoxygine_1_1_event_dispatcher.html#acc098121517eb7c31e83869f9343834e">removeEventListeners</a>(<span class="keywordtype">void</span>* CallbackThis);</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;        <span class="keywordtype">void</span> <a class="code" href="classoxygine_1_1_event_dispatcher.html#a8356d414a0032e1989fc03a6e9ce81b3">removeAllEventListeners</a>();</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;        <span class="keyword">virtual</span> <span class="keywordtype">void</span> dispatchEvent(<a class="code" href="classoxygine_1_1_event.html">Event</a>* event);</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;        <span class="keywordtype">int</span> getListenersCount() <span class="keyword">const</span>;</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;        <span class="keywordtype">int</span> getLastListenerID()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> _lastID; }</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;        <span class="keyword">const</span> EventCallback&amp; getListenerByIndex(<span class="keywordtype">int</span> index)<span class="keyword"> const </span>{ <span class="keywordflow">return</span> (*_listeners)[index].cb; }</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;</div><div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    <span class="keyword">protected</span>:</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;</div><div class="line"><a name="l00065"></a><span class="lineno"><a class="line" href="structoxygine_1_1_event_dispatcher_1_1listenerbase.html">   65</a></span>&#160;        <span class="keyword">struct </span><a class="code" href="structoxygine_1_1_event_dispatcher_1_1listenerbase.html">listenerbase</a></div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;        {</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;            EventCallback cb;</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;            <span class="keywordtype">int</span> id;</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;        };</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;</div><div class="line"><a name="l00071"></a><span class="lineno"><a class="line" href="structoxygine_1_1_event_dispatcher_1_1listener.html">   71</a></span>&#160;        <span class="keyword">struct </span><a class="code" href="structoxygine_1_1_event_dispatcher_1_1listener.html">listener</a> : <span class="keyword">public</span> <a class="code" href="structoxygine_1_1_event_dispatcher_1_1listenerbase.html">listenerbase</a></div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;        {</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;            eventType type;</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;        };</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;        <span class="keywordtype">int</span> _lastID;</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;</div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;        <span class="keyword">typedef</span> std::vector&lt;listener&gt; listeners;</div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;        listeners* _listeners;</div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;    };</div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;}</div><div class="ttc" id="classoxygine_1_1_event_dispatcher_html_acc098121517eb7c31e83869f9343834e"><div class="ttname"><a href="classoxygine_1_1_event_dispatcher.html#acc098121517eb7c31e83869f9343834e">oxygine::EventDispatcher::removeEventListeners</a></div><div class="ttdeci">void removeEventListeners(void *CallbackThis)</div></div>
<div class="ttc" id="classoxygine_1_1_event_dispatcher_html_a8356d414a0032e1989fc03a6e9ce81b3"><div class="ttname"><a href="classoxygine_1_1_event_dispatcher.html#a8356d414a0032e1989fc03a6e9ce81b3">oxygine::EventDispatcher::removeAllEventListeners</a></div><div class="ttdeci">void removeAllEventListeners()</div></div>
<div class="ttc" id="classoxygine_1_1_event_html"><div class="ttname"><a href="classoxygine_1_1_event.html">oxygine::Event</a></div><div class="ttdef"><b>Definition:</b> Event.h:11</div></div>
<div class="ttc" id="classoxygine_1_1_event_dispatcher_html_a0b605ef8cb965cc96b642f9c2649fc40"><div class="ttname"><a href="classoxygine_1_1_event_dispatcher.html#a0b605ef8cb965cc96b642f9c2649fc40">oxygine::EventDispatcher::hasEventListeners</a></div><div class="ttdeci">bool hasEventListeners(void *CallbackThis)</div></div>
<div class="ttc" id="namespaceoxygine_html"><div class="ttname"><a href="namespaceoxygine.html">oxygine</a></div><div class="ttdoc">–oxgl-end–! </div><div class="ttdef"><b>Definition:</b> Actor.h:14</div></div>
<div class="ttc" id="classoxygine_1_1_object_html"><div class="ttname"><a href="classoxygine_1_1_object.html">oxygine::Object</a></div><div class="ttdef"><b>Definition:</b> Object.h:83</div></div>
<div class="ttc" id="structoxygine_1_1_event_dispatcher_1_1listenerbase_html"><div class="ttname"><a href="structoxygine_1_1_event_dispatcher_1_1listenerbase.html">oxygine::EventDispatcher::listenerbase</a></div><div class="ttdef"><b>Definition:</b> EventDispatcher.h:65</div></div>
<div class="ttc" id="structoxygine_1_1_event_dispatcher_1_1listener_html"><div class="ttname"><a href="structoxygine_1_1_event_dispatcher_1_1listener.html">oxygine::EventDispatcher::listener</a></div><div class="ttdef"><b>Definition:</b> EventDispatcher.h:71</div></div>
<div class="ttc" id="classoxygine_1_1_event_dispatcher_html_aea01fffe5e9ce057c6445da2661185e2"><div class="ttname"><a href="classoxygine_1_1_event_dispatcher.html#aea01fffe5e9ce057c6445da2661185e2">oxygine::EventDispatcher::removeEventListener</a></div><div class="ttdeci">void removeEventListener(eventType, const EventCallback &amp;)</div></div>
<div class="ttc" id="classoxygine_1_1_event_dispatcher_html"><div class="ttname"><a href="classoxygine_1_1_event_dispatcher.html">oxygine::EventDispatcher</a></div><div class="ttdef"><b>Definition:</b> EventDispatcher.h:27</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Sun Mar 4 2018 03:50:05 for Oxygine by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.14
</small></address>
</body>
</html>
